<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<?php include "../public/header_main.php";?>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con"><span>编辑垂直运输费清单</span><div class="move_title"></div>
            <div class="page-title-opt-list">
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" lay-submit="" key="temp" lay-filter="add">保存</button>
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" lay-submit="" lay-filter="add">提交</button>
                <span id="page-close" class="page-close" onclick="layer_close()"><i class="layui-icon layui-icon-close"></i></span>
            </div>
        </div>
    </div>
    <div class="main-container" style="padding-bottom: 0!important;">

        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div id="editshi" class="float-r colorlan"></div>
                <div class="budopt"></div>
                <div class="budbox" >
                    <table id="budtable" class="tablewid" openkey="0" onselectstart="return false"></table>
                </div>
            </div>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    var tabHeader;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_main_jian_chui_qing,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $("#editshi").html(res.data.editshi);
                tabHeader = [
                    {type:'numbers',title:''},
                    {field:'sorts',title:'序号'},
                    {type:'cate',field:'name',title:'名称',required:true},
                    {field:'guige',title:'型号'},
                    {field:'num',title:'数量',type:'number'},
                    {field:'monnum',title:'租赁期(月)',type:'number'},
                    {field:'jinfee',title:'进出场安拆费用',type:'number'},
                    {field:'jinallfee',title:'进出场费合计',type:'number',disabled:true,mathduo:'【jinfee】*【num】'},
                    {field:'jichufee',title:'基础费用(含承台及土方)',type:'number'},
                    {field:'jichuallfee',title:'基础费用合计',type:'number',disabled:true,mathduo:'【jichufee】*【num】'},
                    {field:'yuzufee',title:'月租金',type:'number'},
                    {field:'zuhefee',title:'租金合计',type:'number',disabled:true,mathduo:'【yuzufee】*【monnum】*【num】'},
                    {field:'zhigong',title:'指挥工资',type:'number'},
                    {field:'zhiren',title:'指挥人数',type:'number'},
                    {field:'sigong',title:'司机工资',type:'number'},
                    {field:'siren',title:'司机人数',type:'number'},
                    {field:'zhihefee',title:'工资合计',type:'number',disabled:true,mathduo:'(【zhigong】*【zhiren】+【sigong】*【siren】)*【monnum】*【num】'},
                    {field:'qifee',title:'其他费用',type:'number'},
                    {field:'allfee',title:'小计',type:'number',disabled:true,mathduo:'【jinallfee】+【jichuallfee】+【zuhefee】+【zhihefee】+【qifee】'},
                    {field:'explain',title:'备注'},
                ]
                init({
                    dom:'budtable',
                    header:tabHeader,
                    data: res.data.list,
                    isdeaCate: true,
                    chaNavchild: true,
                    count:['num','monnum','jinfee','jinallfee','jichufee','jichuallfee','yuzufee','zuhefee','zhigong','zhiren','sigong','siren','zhihefee','qifee','allfee'],
                });

                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('submit(add)', function(data){
            var keyname = $(this).attr('key') || '';
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}

            var listArr = getBudListData();
            try {
                for (key in listArr){
                    var index = parseInt(key) + 1;
                    if(!listArr[key].name){
                        throw new Error('第'+index+'行，请输入名称');
                    }
                }
            } catch(e) {
                facade.error(e.message);
                return false;
            }
            data.field.list = listToTree(getBudListData());
            data.field.id = param_id;
            facade.ajax({url: ask_main_jian_chui_qing, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    if(keyname === 'temp'){
                        facade.success("保存成功!");
                        $("#editshi").html(res.data.editshi);
                    }else{
                        dataPostTimeOut();
                    }
                }
            });

            return false;
        });

    });


</script>
</body>
</html>
